<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="author" content="zhaozhenguo">
	<title>钻石类型名称管理</title>
	<script language="javascript" src="../script/common.js" type="text/javascript"></script>
	<style>
		.cardTypePhoto{
			padding-top:5px;
			border:1px solid #d0d0d0;
			width:190px;
			height:100px;
			background-color:#FFFFFF;
		}
		.viewTable TD{
			height:20px;
		}
	</style>
	<script language="javascript" type="text/javascript">
	var org = Common.cOrg();			//当前单位	
	var qt = {};						//数据表格对象
	var true_false = [{code:"true",text:"是"},{code:"false",text:"否"}];
	function load(){
		Eui.showNavigation();
		setPages(["listview","amply","editdiv"]);
	 	Common.initDict("diamondType","diamondType","全部");		
		createTable();
	}
	
	function createTable(){
	  	var columns = [];
	  		columns[0] = {type:"checkbox"};
			columns[5]= {title:"操作",width:"15%",render:operationFunc,order:false};	
		qt = new QueryTable("Diamond_type_manager_query","searchForm","datalist",columns,{   //system.xml
			displayColumns:[0,1,2,3,4,5],
			buttons:[
				{value:" 增 加 ",actions:onNew}
			]
		});
	}

	//类型名称的超链接
	function nameFunc(v,r){
		return "<a href=# onclick=lookCardType("+r[0]+")>"+v+"</a>"
	}
	//点击进入类型名称明细信息的方法
	function lookCardType(id){
		Rpc.loadPage("detailsdiv","/basic/card_type_look.html")
		CardStore.cardTypeDetails(id)
		switchPage("amply");
	}
	function operationFunc(v,r){
		return "<div style='color:gray'><a href=# onclick=onEidt('"+r[0]+"')>修改</a> <a href=# onclick=onDelete('"+r[0]+"')>删除</a></div>";
	}
	//显示数据
	function showData(){	
		qt.showTable();			
	}
	function onNew(){
		Rpc.loadPage("editdiv","/aita/diamondTypeView.html")
		Common.initDict(cardtypeform.diamondType,"diamondType","请选择");
		Common.initDict(cardtypeform.weightArea,"weightArea","请选择");
		switchPage('editdiv');
	}
	
	function onDelete(id){
		if(!(showQuestion("确定删除吗?"))){
			return;
		}
		DWR.call("diamondTypeService.deleteDiamondType",id,function(){
			showInformation("删除成功!");
			showData();
			switchPage('listview');
		},{blockScreen:"true"});
	}
	function onEidt(id){
		onNew()
		$("saveBut").onclick=onSave;
		DWR.call("diamondTypeService.loadDiamondType",id,true,function(data){
			var obj = data.diamondType;
			
			if(obj.photo)
		    	$('operPhotoView').innerHTML = "<img id=picsrc src='" + Common.getPhoto(obj.photo) + "' style='border:1px solid #d0d0d0;' height=100>";
			else
		   		$('operPhotoView').innerHTML = "";
			Common.setValues(cardtypeform,obj);
		});
	}
	function showDisabled(value){
		var form =$('cardtypeform')
		var list = []
			if(value){
				list=['baseCardType']
			}else{
				list = ['name','baseCardType','canRevcate',
					'validityDay','depositable','anonymous']
			}
		for(i=0;i<list.length;i++){
			form[list[i]].disabled=true
			form[list[i]].className='disabled'
		}	
	}
	function saveHandle(){
		switchPage('listview');
		showData();
	}
	function onSave(){
		if(!checkForm("cardtypeform"))return;
		var cardTypeObj = Common.getValues(cardtypeform);
	
		DWR.call("diamondTypeService.saveDiamondType",cardTypeObj,function(result){
			showInformation("保存成功!");	
			if (photoform.photoFile.value) {
				Site.uploadPic( photoform, "CardType", result.id, "类型名称",saveHandle)
			}else{
				saveHandle()
			}
			
		},{blockScreen:"true"});
		
	}

	function showValidity(value){
		var form =$('cardtypeform')
		if(value == "true"){
			form.getElements('.display').each(function(tr){
				tr.style.display=""
			})
		}else{
			form.getElements('.display').each(function(tr){
				tr.style.display="none"
			})
			form.auditDaysInAdvance.value=""
			form.daysPerExtention.value=""
		}
	}

	function onBack(){
		switchPage('listview');
	}	
	</script>
</head>
	
<body onload="load()">
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<div id="listview">
		<div class="searchForm">
			<form id="searchForm" name="searchForm">
				<table cellSpacing=0 cellPadding=6 width="100%" border=0>
					<tr>
						<td><label>类型名称</label> <input type="text" name="name" maxlength=20></td>
						<td><label>钻石类型</label> <select name="diamondType"></select></td>
						<td><button type="button" onclick="showData()">查   询</button></td>
					</tr>
				</table>
			</form>
		</div>	
		<div id="datalist"></div>
	</div>
		
		
	<div id=editdiv style="display:none;"></div>
	<div id="amply" style="display:none;">	
		<div id="detailsdiv"></div>
		 <p><button type="button" onclick="onBack()">返 回</button></p>
	</div>			
</body>
</html>	